package com.sefonsoft.dataanalysis.service.impl;

import java.util.Map;

import org.jsoup.nodes.Document;
import org.springframework.stereotype.Service;

import com.sefonsoft.dataanalysis.model.News;
import com.sefonsoft.dataanalysis.service.model.Datas;
import com.sefonsoft.dataanalysis.utils.Tools;


@Service
public class NewsService extends BaseService<News> {

	@Override
	public Datas<News> dataAnalysisByHtml(Document doc) {
		Datas<News> datas = new Datas<News>();
		News news = new News();
		news.setId(Tools.createUUID());
		news.setTitle(doc.select("h1[class='title']").text());
		news.setContent(doc.select("div[id='Zoom']").text());
		String str = doc.select("div[class='lh20']").text();
		String source  = str.substring(str.indexOf("来源：")+3,str.indexOf("发布："));
		String time  = str.substring(str.indexOf("发布：")+3,str.length());
		news.setSource(source);
		news.setPublicTime(time);
		datas.getDatas().add(news);
		return datas;
	}

	@Override
	public Datas<News> dataAnalysisByJson(String jsonStr) {
		/**
		 * 做json特殊处理
		 */
//		if (StringUtils.isBlank(jsonStr)) {
//		}
//		JSONObject obj = JSONObject.parseObject(jsonStr);
		return null;
	}
	
	@Override
	public void generateMap(Map<String, Object> map) {
		//做固定查询条件组装
		
	}
	
	@Override
	public Class<News> getTClass() {
		return News.class;
	}

	@Override
	public Type getSourceType() {
		return Type.HTML;
	}


}
